<?php
	require("../APP_ROOT.php");
	require(__ROOT__."/class/mysqlpdo.class.php");
	/** 操作类型 **/
	$operation = $_REQUEST["operation"];
	$pdo = new mysqlpdo();
	switch($operation) {
		case "add"://添加
			$params = $_POST["params"];
			$params = json_decode($params, true);//true 强制转换为数组
			$menuId = 0;
			$firstMenu = 0;
			$menuName = null;
			$actionType = 0;
			$actionValue = null;
			$rank = 0;
			foreach($params as $obj) {
				if($obj["name"] == "menuId") {
					$menuId = intval($obj["value"]);
				} else if($obj["name"] == "firstMenu") {
					$firstMenu = intval($obj["value"]);
				} else if($obj["name"] == "menuName") {
					$menuName = $obj["value"];
				} else if($obj["name"] == "actionType") {
					$actionType = $obj["value"];
				} else if($obj["name"] == "actionValue") {
					$actionValue = $obj["value"];
				} else if($obj["name"] == "rank") {
					$rank = intval($obj["value"]);
				}
			}
			echo $menuName;
			/*if($menuId > 0) {//更新
				$pdo -> update("t_custom_menu", 
					array("parent_menu_id" => $firstMenu, "menu_name" => $menuName, "action_type" => $actionType, "action_value" => $actionValue, "rank" => $rank), 
					array("id" => $menuId));
			} else {//插入
				$pdo -> insert("t_custom_menu", 
					array("parent_menu_id" => $firstMenu, "menu_name" => $menuName, "action_type" => $actionType, "action_value" => $actionValue, "rank" => $rank));
			}*/
			//echo "操作成功!";
			/*header("Location:../custom_menu.php");
			echo "<script type='text/javascript'>history.go(-1);alert('操作成功!');</script>";*/
			break;
		case "edit"://编辑
			$menuId = $_REQUEST["id"];
			$row = $pdo -> fetch("t_custom_menu", "*", array("id" => $menuId));
			echo json_encode($row);
			break;
		case "del"://删除
			$menuId = $_REQUEST["id"];
			echo json_encode($operation);
			break;
		case "getFirstMenu"://获取一级菜单
			$row = $pdo -> fetchAll("t_custom_menu", "id, menu_name", array("parent_menu_id" => 0));
			echo json_encode($row);
			break;
		default :
			break;
	}
	
?>